﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Demo.Framework.Algorithm.Sort
{
    /* List - X0, X1, X2 ..... XN-1
     * Set i=0
     * Scan i=1 to N-1 and find the Min Element (at K)
     * Swap X0, XK
     * Increment i
     * Repeat
     * 
     * Advantages
     * 
     * Disadvantages
     * */
    class SelectionSort<T> : AbstractSort<T>
        where T : IComparable
    {
        public override void Sort(T[] list)
        {
            int count = list.Length;
            for (int i = 0; i < count; i++)
            {
                int min = i;
                for (int j = i+1; j < count; j++)
                {
                    if(IsLess(list[j], list[min]))
                    {
                        min = j;
                    }                    
                }
                Swap(list, i, min);
            }
        }

        
    }
}
